﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AllInOne.Pages
{
    /// <summary>
    /// ModifyPhoto.xaml 的交互逻辑
    /// </summary>
    public partial class ModifyPhonePage : Page
    {
        private MainWindow parent;
        public ModifyPhonePage()
        {
            InitializeComponent();
        }

        public ModifyPhonePage(MainWindow parent)
        {
            InitializeComponent();
            this.parent = parent;
        }

        public void InitPage()
        {
            if (this.parent.businessInfo.sjhm != null)
            {
                this.txtSjhm.Text = this.parent.businessInfo.sjhm;
            }
            else {
                this.txtSjhm.Text = this.parent.drivingLicence.sjhm;
            }
            this.imgTitle.Source = new BitmapImage(new Uri(this.parent.businessInfo.getImgTitleUrl()));

        }


        private void BtnService_MouseUp(object sender, MouseButtonEventArgs e)
        {
            
            string sjhm = txtSjhm.Text;
            if (sjhm != null && sjhm.Length < 11)
            {
                TextBlock btn = (TextBlock)sender;
                string key = btn.Text;
                txtSjhm.Text = sjhm + key;
            }
        }

        private void BtnClear_MouseUp(object sender, MouseButtonEventArgs e)
        {
            txtSjhm.Text = "";
            

        }

        private void BtnBackspace_MouseUp(object sender, MouseButtonEventArgs e)
        {
            string sjhm = txtSjhm.Text;
            if (sjhm != null && sjhm.Length > 0)
            {
                txtSjhm.Text = sjhm.Substring(0, sjhm.Length - 1);
            }
        }

        private void BtnSubmit_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (verifyPhone())
            {
                this.parent.ModifyPhone(this.txtSjhm.Text);
            }
        }

        private bool verifyPhone()
        {
            return true;
        }

        private void BtnBackToIndex_MouseUp(object sender, MouseButtonEventArgs e)
        {
            this.parent.ResetIndex();
        }

        private void BtnCancel_MouseUp(object sender, MouseButtonEventArgs e)
        {

        }
    }
}
